package it.disim.tlp.webreputation.exceptions;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class AggregatorLogger {
	private static final String logDirectory = "logs/";

	
	/**
	 * This constructor takes a String and an Exception and writes
	 * the stacktrace inside a file in the logs directory creating its
	 * name from string passed as argument and the current date.
	 * @param A String and a valid exception.  
	 */
	public static void logging(String pluginName,Exception e){
		FileOutputStream fos = null;
		Date date = new Date();
		DateFormat df = new SimpleDateFormat("dd-MM-yyyy (HH:mm:ss)");
		try {
			fos = new FileOutputStream(new File(logDirectory+pluginName+" ["+df.format(date))+"]");
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}  
		PrintStream ps = new PrintStream(fos);  
		e.printStackTrace(ps);
	}
}
